<template>
    <view class="content">
        <van-popup
            position="bottom"
            @click-overlay="closePopup"
            :show="show"
            round
            z-index="104"
            custom-style="width: 100%;background:#ffffff;overflow: hidden; ">
            <view class="popup-content" :style="'height:' + (popupHeight) + 'px'">
                <!-- <scroll-view :refresher-enabled="false" class="scroll-content" scroll-y :lower-threshold="80"  show-scrollbar="false"> -->

                <view class="popup-main">
                    <view style="display: flex; justify-content: space-between;">
                        <view class="popupTitle"> {{ title }}</view>
                        <van-icon name="cross"  size="15" @click="closePopup" />
                    </view>

                    <view class="cancelPopup-wrapper " >
                        <!-- <view class="popupTips">取消后无法恢复，优惠券、积分可退回</view> -->
                        <view class="popupSubtitle">请选择退款原因</view>
                        <view class="sort">
                            <radio-group @change="radioChange">
                                <label class="popup_item itemLeft" v-for="(item,index) in popupData" :key="index" :id="item.key">
                                    <radio color="#FF6203" :value="item.key" :checked="item.isChecked" class="radio" />
                                    <view style="margin-left:6px;">{{ item.text }}</view>
                                </label>
                            </radio-group>
                        </view>

                    </view>

                    <van-toast id="van-toast" />
                </view>
                <!-- </scroll-view> -->
                <!-- <view class="goodsAction nav_box">
                    <button type="warn" class="checkBtn" @click="submit">下一步</button>
                </view> -->
                 <view class="btn-area">
                    <van-button type="primary" class="" @click="submit">下一步</van-button>
                </view>
            </view>
        </van-popup>
    </view>
</template>

<script>
import Toast from '@/wxcomponents/vant/toast/toast'
export default {
    props: {
        show: {
            type: Boolean,
            default: () => false
        },
        selectedReason: {
            type: String,
            default: () => ''
        },
        // popupBiaoshi:{
        //     type: Number,
        //     default: () => 0
        // }
    },
    data () {
        return {
            curS: 0,
            curSName: '',
            date: '',
            title: '退款类型',
            option: {},
            url: '',
            stepperValue: 1,
            popupData: [

                {
                    key: 1,
                    text: '成分与描述不符'
                },
                {
                    key: 2,
                    text: '协商一致退款'
                },
                {
                    key: 3,
                    text: '发错货物'
                },
                {
                    key: 4,
                    text: '质量问题'
                },
                {
                    key: 5,
                    text: '少件'
                },
                {
                    key: 6,
                    text: '其他'
                }

            ],
            popupHeight: '500',

            isCancel: true,
            REASON_MAPPING :{
                '成分与描述不符': 'INGREDIENTS_NOT_MATCH_DESCRIPTION',
                '协商一致退款': 'CONSENSUS_REFUND',
                '发错货物': 'WRONG_GOODS',
                '质量问题': 'QUALITY_PROBLEM',
                '少件': 'MISSING_ITEMS',
                '其他': 'OTHER'
            },
            selectedReasonType:''
        }
    },

    computed: {
    },

    watch: {
    //   popupBiaoshi: {
    //       handler(v) {
    //           console.log(v, 'v')
    //           if (v === 0) {
    //               this.title = '商品排序'
    //               this.popupHeight='300'
    //           } else if (v === 1) {
    //               this.title = '全部分类'
    //               this.popupHeight='350'
    //           } else {
    //               this.title = '价格区间'
    //               this.popupHeight='200'
    //           }
    //       },
    //       deep: true
    //   }
    },
    onLoad () {
        // if (this.popupBiaoshi===0) {
        //     this.title = '商品排序'
        // } else if (this.popupBiaoshi===2) {
        //     this.title = '价格区间'
        // }
    },
    onReady () {
        this.popupData.forEach(ele => {
            this.$set(ele, 'isChecked', ele.text === this.selectedReason)
        })
    },

    methods: {
        // 选口味
        // onClickSort(val,e,item){
        //     console.log(val,e,item,'商品排序')
        //     this.curS=val
        //     this.curSName=item.text
        // },
        // 单选框
        radioChange (e) {
            console.log('radio发生change事件，携带value值为：', e.detail.value)
            const REASON_MAPPING = {
            '成分与描述不符': 'INGREDIENTS_NOT_MATCH_DESCRIPTION',
            '协商一致退款': 'CONSENSUS_REFUND',
            '发错货物': 'WRONG_GOODS',
            '质量问题': 'QUALITY_PROBLEM',
            '少件': 'MISSING_ITEMS',
            '其他': 'OTHER'
        };
            this.popupData.forEach((item, index) => {
                console.log(index, 'index',item, typeof (item.key), typeof (e.detail.value), Number(item.key) === Number(e.detail.value))
                if (Number(item.key) === Number(e.detail.value)) {
                    item.isChecked = true
                    this.selectedReasonType = REASON_MAPPING[item.text];
                } else {
                    item.isChecked = false
                }
            })
        },

        // 关闭弹窗
        closePopup () {
            this.isCancel = false
            this.$emit('closePopup', this.isCancel)
        },

        submit () {
            console.log(this.selectedReasonType)
            this.closePopup()
            this.$emit('next', this.selectedReasonType)

        }

    }

}
</script>
<style lang="scss" scoped>
// @import '@/styles/variables.scss';

::v-deep .van-button__text {
    display: flex !important;
    flex-direction: column !important;
}
// 提示框
.popup-content {
    padding: 24px;
    font-size: 12px;
    background: #ffffff;
    border-radius: 16px;
    overflow: hidden;
    height: 50%;

    .popup-main {
        height: 100%;
    }

    .popupTitle {
        font-size: 20px;
        text-align: left;
        color: #111111;
        line-height: 20px;
    }

    .cancelPopup-wrapper {
        padding-top: 23px;
    }

    .popupTips{
        font-size: 12px;
        text-align: left;
        color: #666666;
        background-color: #F0F0F0;
        padding-top: 10px ;
        padding-bottom: 10px;
        padding-left: 15px;
    }
    // 副标题
    .popupSubtitle{
        font-size: 14px;
        text-align: left;
        color: #666666;
        line-height: 14px;
        margin-top: 15px;
        margin-bottom: 30px;
    }

    // 商品排序
    .sort {
        .popup_item {
            font-size: 14px;
            text-align: left;
            color: #111111;
            line-height: 14px;
            margin-bottom: 20px;

            &.active {
                font-weight: bolder;
                color: #FF6203;
            }
        }

        .popup_item:last-child {
            margin-bottom: 0px;
        }
    }
    .itemLeft{
        display: flex;
        align-items: center;
    }

    // 价格区间
    .price_range {
        display: flex;
        justify-content: space-around;
        align-items: center;
    }

    // 加入购物车按钮
    .goodsAction {
        margin-top: 22px;
        width: calc(100% - 48px);
        text-align: center;
        height: 70px;
    }

    .button {
        width: 100%;
        font-size: 16px;
        color: #ffffff;
        height: 44px;
        line-height: 44px;
        border-radius: 25px;
        border-style: initial !important;
        padding: 0 !important;
        background: #FF6203 !important;
    }
}

.checkBtn {
    background-color: #FF6203;
    border: none;
    border-radius: 38rpx;
    font-size: 28rpx;
    text-align: center;
    color: #FFFFFF;
    height: 86rpx;
    line-height: 86rpx;

    width: 100%;
}
::v-deep .van-button--primary {
  width: 100%;
  height: 86rpx;
  border-radius: 50rpx;
  background: #ff6203;
  margin-top: 32rpx;
  font-size: 28rpx;
}

.l20 {
    margin-left: 20px;
}

.r13 {
    margin-right: 13px;
}

.r8 {
    margin-right: 8px;
}
</style>
